package com.me.demoanimation;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;

import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Stage;

import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;


public class demoAnimation implements ApplicationListener {
	private static final int NUMBER_OF_FRAMES = 10;
	boolean isLocked = false;
	int count=0;
	float k=0f;
	
	Animation numberAnimation;
	Texture numberSheet[];
	TextureRegion[] numberFrames;
	SpriteBatch spriteBatch;
	TextureRegion currentFrame;
	TextureRegion currentFrame2;
	TextureRegion currentFrame3;
	TextureRegion currentFrame4;
	TextureRegion currentFrame5;
	Stage stage ;
	Skin skin = new Skin();
	
	float stateTime;
	
	@Override	
	public void create() {	
		Gdx.input.setInputProcessor(stage);
		numberFrames = new TextureRegion[NUMBER_OF_FRAMES];
		numberSheet = new Texture[NUMBER_OF_FRAMES];
		for(int i=0;i<NUMBER_OF_FRAMES;i++) {
			numberSheet[i] = new Texture(Gdx.files.internal("data/"+i+".jpg"));
			numberFrames[i] = new TextureRegion(numberSheet[i]);
		}
		
		stage = new Stage();
		TextureRegion upRegion = numberFrames[2];
		TextureRegion downRegion = numberFrames[3];
		Table table = new Table();
		table.setFillParent(true);
		stage.addActor(table);
		BitmapFont buttonFont = new BitmapFont();
		
		TextButtonStyle style = new TextButtonStyle();
		style.up = new TextureRegionDrawable(upRegion);
		style.down = new TextureRegionDrawable(downRegion);
		style.font = buttonFont;
	//	TextButton button1 = new TextButton("button 1",style );
		Button button1 = new Button(skin,"button1");
		table.add(button1);
//		TextButton button2 = new TextButton("button 2",style );
		Button button2 = new Button(skin,"button2");
		table.add(button2);
		
		
		
		numberAnimation = new Animation(1f,numberFrames);
		spriteBatch = new SpriteBatch();
		stateTime = 0f;
		
	}

	@Override
	public void dispose() {
		stage.dispose();
	}

	@Override
	public void render() {
		
		
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
		//System.out.println(stateTime);
		currentFrame  = numberFrames[2];
		currentFrame2 = numberFrames[1];
		currentFrame3 = numberFrames[3];
		currentFrame4 = numberFrames[5];
		currentFrame5 = numberFrames[3];
//		currentFrame  = numberAnimation.getKeyFrame(stateTime,true);
//		currentFrame2 = numberAnimation.getKeyFrame(stateTime*10,true);
//		currentFrame3 = numberAnimation.getKeyFrame(stateTime*100,true);
//		currentFrame4 = numberAnimation.getKeyFrame(stateTime*1000,true);
//		currentFrame5 = numberAnimation.getKeyFrame(stateTime*10000,true);
		spriteBatch.begin();	
		
		spriteBatch.draw(currentFrame ,450 ,400);
		spriteBatch.draw(currentFrame2,482 ,400);
		spriteBatch.draw(currentFrame3,514 ,400);
		spriteBatch.draw(currentFrame4,546 ,400);
		spriteBatch.draw(currentFrame5,578 ,400);
		count++;
		
		spriteBatch.end();
		stage.act(Gdx.graphics.getDeltaTime());
		stage.draw();
		
		Table.drawDebug(stage);
	}

	@Override
	public void resize(int width, int height) {
		stage.setViewport(640, 480, true);
	}

	@Override
	public void pause() {
		
	}

	@Override
	public void resume() {
	}
}
